package Util;
/**
 * 用正则表达式约束用户账号规范
 */

import javax.swing.*;

public class Inspectionrules {
    //定义由用户名规则
    public final static String uid = "[a-zA-Z0-9]{6,10}";
    //定义手机号规则
    public final static String tell = "\\d{11}";//11位手机号
    //定义用户密码规则
    public final static String upas = "\\w{6,18}";// \\w表示数字字母下划线都可

    public static boolean checkAccount(JFrame jf, String userAccount) {
        if (!userAccount.matches(uid)) {
            JOptionPane.showMessageDialog(jf, "The user name is 6-10 digits, composed of letters and numbers");//用户名为6-10位，由字母和数字组成
            return false;
        }
        return true;
    }
    public static boolean checkTel(JFrame jf, String userTel) {
        if (!userTel.matches(tell)) {
            JOptionPane.showMessageDialog(jf, "Mobile phone number is 11 digits!");//手机号为11位数字！
            return false;
        }
        return true;
    }
    public static boolean checkPass(JFrame jf, String userPass) {
        if (!userPass.matches(upas)) {
            JOptionPane.showMessageDialog(jf, "The user password is 6-18 digits, which is composed of letters and numbers with hull underline");//用户密码为6-12位，由字母、数字赫尔下划线组成
            return false;
        }
        return true;
    }
}
